From 1f125d1e7e7ca084ff2f9df7f7b0f6191abec376 Mon Sep 17 00:00:00 2001 From: theanarkh Date: Sun, 6 Jul 2025 01:33:23 +0800 Subject: [PATCH] [PATCH] os: fix GetInterfaceAddresses memory lieaky MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/58940 Reviewed-By: Juan José Arboleda Reviewed-By: Chengzhong Wu Gbp-Pq: Topic sec Gbp-Pq: Name 15-fix-os-getinterface-addresses-leak.patch --- src/node_os.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/node_os.cc b/src/node_os.cc index ce2af8d83..ddaf61d5e 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -192,6 +192,9 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo& args) { return args.GetReturnValue().SetUndefined(); } + auto cleanup = + OnScopeLeave([&]() { uv_free_interface_addresses(interfaces, count); }); + Local no_scope_id = Integer::New(isolate, -1); std::vector> result; result.reserve(count * 7); @@ -243,7 +246,6 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo& args) { } } - uv_free_interface_addresses(interfaces, count); args.GetReturnValue().Set(Array::New(isolate, result.data(), result.size())); } -- 2.30.2